package org.jeecg.modules.com.pointoperation.service.impl;


import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sun.org.apache.xpath.internal.operations.Bool;
import org.jeecg.modules.com.pointoperation.entity.Userspoint;
import org.jeecg.modules.com.pointoperation.mapper.UserspointMapper;
import org.jeecg.modules.com.pointoperation.service.IUserspointService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Description: userspoint
 * @Author: jeecg-boot
 * @Date:   2020-05-05
 * @Version: V1.0
 */
@Service
public class UserspointServiceImpl extends ServiceImpl<UserspointMapper, Userspoint> implements IUserspointService {
//    @Autowired
//    private UserspointMapper userspointMapper;
    @DS(value = "multi-datasource1")
    public List<Userspoint> listAllUserspoint(){

        return this.getBaseMapper().selectList(null);
    }

    @DS(value = "multi-datasource1")
    public IPage<Userspoint> pageChooseDS(com.baomidou.mybatisplus.core.metadata.IPage<Userspoint> page,
                                          com.baomidou.mybatisplus.core.conditions.Wrapper<Userspoint> queryWrapper) {

        return this.page(page, queryWrapper);
    }

    @DS(value = "multi-datasource1")
    @Transactional
    public Boolean updateUserPointNumber(Userspoint userspoint) {

        LambdaUpdateWrapper<Userspoint> lambdaUpdateWrapper = new LambdaUpdateWrapper<>(userspoint).setSql("pointTotal = pointTotal + 1");

//        UpdateWrapper updateWrapper = new UpdateWrapper(userspoint).set("count",1);
        this.getBaseMapper().update(userspoint, lambdaUpdateWrapper);
        return true;
    }

}
